<?php

$userid = $_SESSION['ss_mb_id'];
$_temp = sql_fetch("SELECT mb_no,mb_division from g4_member WHERE `mb_id`='$userid' LIMIT 1");
$studentno = $_temp['mb_no'];

if(!$_SESSION || !$studentno) {
    alert("로그인한 학생만 접근할 수 있습니다.");
        
} else if($_temp['mb_division'] != "학생" && $_temp['mb_division'] != '최고관리자' && $_temp['mb_division'] != '관리자') {
    alert('로그인한 학생만 접근할 수 있습니다.');
}


// 오늘 수업 구하기 global 

$year = date('Y');
$month= date('m');
$date = 'w_'.strtolower(date('D'));

$sql = "SELECT c.starttime, c.name, g.mb_hp, g.mb_nick, g.mb_name FROM course c, g4_member g, course_order co WHERE c.no = co.course AND co.student = g.mb_no AND g.mb_id= '$userid' AND c.month = $month AND c.year = $year AND c.$date > 0 AND co.status = 2";

$_res = sql_query($sql);
$_todayCourseData = array();
while($_ret = sql_fetch_array($_res)) {
    $_temp = getAMPMtime($_ret['starttime']);
    $_ret['ampm'] = $_temp['ampm'];
    $_ret['han'] = $_temp['han'];
    $_ret['time'] = $_temp['time'];
    $_iconset = date('i') == $_ret['starttime'] ? 'on' : 'off';
    $_todayCourseData[] = $_ret; 
}

if($tpl) {
    $tpl->assign('todayCourse', $_todayCourseData);
}
// 오늘수업 구하기 끝 ;

function _makeOptionList($arrayString, $indexKey=NULL) {
    $_temp = NULL; 
    foreach($arrayString as $key => $value) {
        $selected = ($key == $indexKey) ? "selected=selected": NULL;
        $_temp.= "<option value=\"$key\" $selected>$value</option>";
    }
    return $_temp;
}

function _makeSqlWhere($_sqlWhere, $key, $value, $isLike = FALSE) {
    $equal = '=';
    if($isLike) {
        $equal = ' LIKE '; 
    }
    if($_sqlWhere && $key && $value) {
        return $_sqlWhere." AND $key $equal $value"; 
    } else if($key && $value) {
        return " WHERE $key $equal $value"; 
    }
    return $_sqlWhere; 
}

function makelink($notkey) {
    global $_GET;
    $link = '&';
    foreach($_GET as $key => $value) {
        if(!in_array($key, $notkey)) {
            $link.= $key.'='.urlencode($value).'&';
        }
    }
    return $link;
}
